import {FilterConditionFormTypeEnum} from "./filterConditionFormTypeEnum";
import {FilterConditionFormLeftTypeEnum} from "./filterConditionFormLeftTypeEnum";
/**
 * Created by Administrator on 2017/4/21.
 */
export class FilterConditionForm {
    left: string
    right: any
    op: string
    data: any
    type: FilterConditionFormTypeEnum
    leftType: FilterConditionFormLeftTypeEnum = FilterConditionFormLeftTypeEnum.string
    common: boolean = true;


    constructor(left: string, op: string, type: FilterConditionFormTypeEnum, leftType?: FilterConditionFormLeftTypeEnum, common?: boolean) {
        this.left = left
        this.op = op
        this.type = type
        if (leftType) {
            this.leftType = leftType
        }
        if (common != undefined) {
            this.common = common
        }
    }

    operate(): FilterConditionForm {
        if (this.type == FilterConditionFormTypeEnum.common) {
            this.right = this.data
        } else if (this.type == FilterConditionFormTypeEnum.money) {
            this.right = this.data * 100
        } else if (this.type == FilterConditionFormTypeEnum.time) {
            this.right = "Date(" + this.data.epoc * 1000 + ")"
            console.log(this.right)
        }
        return this
    }

    isUseful(): boolean {
        if (this.data || this.op == "eager") {
            return true;
        }
        return false
    }


}

